<template>
    <div>
        <el-page-header @back="gotoRoute('/eva-project/pager')" :content="'项目:' + meta.project.name + '设置'">
        </el-page-header>
        <el-tabs v-model="meta.active_name">
            <el-tab-pane label="项目测评表设置" name="seveth">
                <eva-project-form-pager v-if="meta.project_id" :project_id="meta.project_id"
                    :is_finished="meta.is_finished">

                </eva-project-form-pager>
            </el-tab-pane>
            <el-tab-pane label="评测主体设置" name="second">
                <eva-project-owner-pager v-if="meta.project_id && meta.group_type >= 0" :project_id="meta.project_id"
                    :group_type="meta.group_type" :is_finished="meta.is_finished">

                </eva-project-owner-pager>
            </el-tab-pane>
            <el-tab-pane v-if="leader" label="领导人员设置" name="third">
                <eva-project-leader-pager v-if="meta.project_id" :project_id="meta.project_id"
                    :is_finished="meta.is_finished">

                </eva-project-leader-pager>
            </el-tab-pane>
            <el-tab-pane v-if="newLeader" label="新提拔干部设置" name="fourth">
                <eva-project-new-leader-pager v-if="meta.project_id" :project_id="meta.project_id"
                    :is_finished="meta.is_finished">

                </eva-project-new-leader-pager>
            </el-tab-pane>
            <el-tab-pane v-if="extDirector" label="外部董事设置" name="fifth">
                <eva-project-ext-director-pager v-if="meta.project_id" :project_id="meta.project_id"
                    :is_finished="meta.is_finished"></eva-project-ext-director-pager>
            </el-tab-pane>
            <el-tab-pane label="二维码设置" name="sixth">
                <eva-project-user v-if="meta.project_id" :project_id="meta.project_id" :is_finished="meta.is_finished">

                </eva-project-user>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<script>
import { BaseApi } from "../../api/common/base-api"
import { sharedConfig } from "../shared/BaseCurd"
import EvaProjectOwnerPager from "./owner/Pager.vue"
import EvaProjectLeaderPager from "./leader/Pager.vue"
import EvaProjectNewLeaderPager from "./new-leader/Pager.vue"
import EvaProjectExtDirectorPager from "./ext-director/Pager.vue"
import EvaProjectFormPager from "./form/Pager.vue"
import EvaProjectUser from "./user/Pager.vue"
const form_api = new BaseApi({ prefix: "/eva-project-form" })
const proj_api = new BaseApi({ prefix: "/eva-project" });
export default {
    name: "Setting",
    components: {
        EvaProjectFormPager,
        EvaProjectOwnerPager,
        EvaProjectLeaderPager,
        EvaProjectNewLeaderPager,
        EvaProjectExtDirectorPager,
        EvaProjectUser
    },
    data() {
        return {
            meta: {
                is_finished: Boolean(this.$route.query.is_finished),
                project: { name: "" },
                active_name:
                    this.$route.query.name || "seveth",
                project_id: this.$route.query.id,
                group_type: this.$route.query.group_type,
                userTypes: [],
            }
        }
    },
    async mounted() {
        const forms = await form_api.findList({ where: { project_id: this.meta.project_id } })
        this.meta.userTypes = forms.data.map(f => f.user_type);
        const project = await proj_api.findByPk({ pk: this.meta.project_id });
        this.meta.project = { ...project.data };
    },
    methods: { ...sharedConfig.methods },
    computed: {
        leader() {
            return this.meta.userTypes.find(u => u == "0") >= 0;
        },
        newLeader() {
            return this.meta.userTypes.find(u => u == "1");
        },
        extDirector() {
            return this.meta.userTypes.find(u => u == "2");
        }
    }
}
</script>